package com.itheima.chapter12.xml;

import com.sun.org.apache.xml.internal.resolver.readers.SAXCatalogReader;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.List;

public class ParseXml {
    public static void main(String[] args) throws DocumentException {
        //创建解析器读写对象
        SAXReader reader = new SAXReader();
        //关联要解析的xml文件，创建Document对象
        Document document = reader.read("D:\\IdeaProjects\\BasicCode\\MyIdeaTest\\src\\com\\itheima\\chapter12\\xml\\mstus.xml");
        //获取根标签
        Element rootElement = document.getRootElement();
        //System.out.println(rootElement);
        //子标签集合
        List<Element> elements = rootElement.elements();
        for (Element element : elements) {
            //System.out.println(element);
            System.out.println(element.getQName());
            System.out.println(element.getName());
            //element.getName().
            System.out.println(element.attributeValue("id"));
            Element nameelement = element.element("name");
            Element ageelement = element.element("age");
            System.out.println(nameelement);
            System.out.println(ageelement);
            System.out.println(nameelement.getText());
            System.out.println(ageelement.getText());

        }


    }
}
